package com.spring.sunflower.widget;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.lxj.xpopup.core.BubbleAttachPopupView;
import com.lxj.xpopup.interfaces.OnSelectListener;
import com.spring.sunflower.R;

/**
 * Description: 自定义气泡Attach弹窗
 * Create by lxj, at 2019/3/13
 */
public class CustomBubbleAttachPopup extends BubbleAttachPopupView implements View.OnClickListener {
    private OnSelectListener listener;
    private boolean isFollowed, isBlacked;

    public CustomBubbleAttachPopup(@NonNull Context context, boolean isBlacked, boolean isFollowed, OnSelectListener listener) {
        super(context);
        this.listener = listener;
        this.isFollowed = isFollowed;
        this.isBlacked = isBlacked;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.custom_bubble_attach_popup;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        TextView tvFollowed = findViewById(R.id.tv_followed);
        TextView tvBlack = findViewById(R.id.tv_black);
        TextView tvReport = findViewById(R.id.tv_report);
        TextView tvShare = findViewById(R.id.tv_share);
        tvShare.setVisibility(GONE);
        tvBlack.setText(isBlacked ? "解除拉黑" : "拉黑");
        tvFollowed.setText(isFollowed ? "取消关注" : "关注");
        tvFollowed.setOnClickListener(this);
        tvBlack.setOnClickListener(this::onClick);
        tvReport.setOnClickListener(this::onClick);
        tvShare.setOnClickListener(this::onClick);
//        tv.setOnClickListener(new OnClickListener() {
//            @Override
//            public void onClick(View v) {
////                tv.setText(tv.getText() + "\n 啊哈哈哈啊哈");
////                tv.setText("\n 啊哈哈哈啊哈");
//                dismiss();
//                if (listener != null) {
//                    listener.onSelect(0, "Hello");
//                }
//            }
//        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_followed:
                if (listener != null) {
                    listener.onSelect(0, "");
                }
                break;
            case R.id.tv_black:
                if (listener != null) {
                    listener.onSelect(1, "");
                }
                break;
            case R.id.tv_report:
                if (listener != null) {
                    listener.onSelect(2, "举报");
                }
                break;
            case R.id.tv_share:
                if (listener != null) {
                    listener.onSelect(3, "分享");
                }
                break;
        }
        dismiss();
    }
}
